#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pymongo

# pylint: disable-msg=R0904

# mongo wrapper class imposing safe write (see "write concern")
# change w value to change the number of write to wait for
class SafeMongoClient(pymongo.MongoClient):
    def __init__(self, host=None, port=None):
        pymongo.MongoClient.__init__(self, host, port, w=1, j=True)
        
    def close(self):
        try:
            pymongo.MongoClient.close(self)
        except:
            pass
        
#TODO: complete these methods
class MongoTools(object):
    @staticmethod
    def delete_collection(database_name, collection_name):
        pass
    
    @staticmethod
    def delete_database(database_name):
        pass
    
        
    

# wrapper class for mongorestore functionality
class MongoRestore(object):
    @staticmethod
    def restore(database, collection, dumpfile, host=None, port=None, user=None, password=None):
        request = 'pymongo'
        if database:
            request += ' --db %s' % (database)
        if collection:
            request += ' --collection %s' % (collection)
        if host:
            request += ' --host %s' % (host)
        if dumpfile:
            pass
            
#         h = pymongo.MongoClient.HOST
#         p = pymongo.MongoClient.PORT
#         if host:
#             h = host
#         if port:
#             p = port
        
#         mongorestore --collection people --db accounts dump/accounts/people.bson
#             
#         os.system('notepad.exe "%s" &' % (module_full))
#         
#         mongorestore --host mongodb1.example.net --port 37017 --username user --password pass /opt/backup/mongodump-2011-10-24
